-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
89 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,100 +176,100 @@ func TestParseNodeInfo(t *testing.T) { | |
} | ||
} | ||
|
||
func TestDeployNodes(t *testing.T) { | ||
// Create a temporary file with JSON content | ||
tempFile, err := ioutil.TempFile("", "test.json") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.Remove(tempFile.Name()) | ||
// func TestDeployNodes(t *testing.T) { | ||
// // Create a temporary file with JSON content | ||
// tempFile, err := ioutil.TempFile("", "test.json") | ||
// if err != nil { | ||
// t.Fatal(err) | ||
// } | ||
// defer os.Remove(tempFile.Name()) | ||
|
||
// Define your sample JSON content | ||
jsonContent := `{ | ||
"master": "[email protected]", | ||
"workers": { | ||
"cloud": [ | ||
], | ||
"edge": [ | ||
] | ||
} | ||
}` | ||
// // Define your sample JSON content | ||
// jsonContent := `{ | ||
// "master": "[email protected]", | ||
// "workers": { | ||
// "cloud": [ | ||
// ], | ||
// "edge": [ | ||
// ] | ||
// } | ||
// }` | ||
|
||
// Write the JSON content to the temporary file | ||
err = ioutil.WriteFile(tempFile.Name(), []byte(jsonContent), 0644) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
// // Write the JSON content to the temporary file | ||
// err = ioutil.WriteFile(tempFile.Name(), []byte(jsonContent), 0644) | ||
// if err != nil { | ||
// t.Fatal(err) | ||
// } | ||
|
||
criteriaTable := map[string]string{ | ||
"Golang": "1.19.10", | ||
"containerd": "1.6.18", | ||
"runc": "1.1.4", | ||
"CNI": "1.2.0", | ||
"Kubernetes": "1.25.9", | ||
} | ||
// criteriaTable := map[string]string{ | ||
// "Golang": "1.19.10", | ||
// "containerd": "1.6.18", | ||
// "runc": "1.1.4", | ||
// "CNI": "1.2.0", | ||
// "Kubernetes": "1.25.9", | ||
// } | ||
|
||
// Capture standard output | ||
r, w, err := os.Pipe() | ||
if err != nil { | ||
t.Fatalf("Error creating pipe: %v", err) | ||
} | ||
defer r.Close() | ||
defer w.Close() | ||
// // Capture standard output | ||
// r, w, err := os.Pipe() | ||
// if err != nil { | ||
// t.Fatalf("Error creating pipe: %v", err) | ||
// } | ||
// defer r.Close() | ||
// defer w.Close() | ||
|
||
// Redirect standard output to the pipe | ||
oldStdout := os.Stdout | ||
os.Stdout = w | ||
defer func() { | ||
os.Stdout = oldStdout | ||
}() | ||
// // Redirect standard output to the pipe | ||
// oldStdout := os.Stdout | ||
// os.Stdout = w | ||
// defer func() { | ||
// os.Stdout = oldStdout | ||
// }() | ||
|
||
// // Call the function to be tested | ||
deployNodes(tempFile.Name()) | ||
// // // Call the function to be tested | ||
// deployNodes(tempFile.Name()) | ||
|
||
// Capture stdout | ||
w.Close() | ||
var capturedOutput strings.Builder | ||
_, err = io.Copy(&capturedOutput, r) | ||
if err != nil { | ||
t.Fatalf("Error reading from pipe: %v", err) | ||
} | ||
t.Logf("captop: %v", capturedOutput.String()) | ||
// // Capture stdout | ||
// w.Close() | ||
// var capturedOutput strings.Builder | ||
// _, err = io.Copy(&capturedOutput, r) | ||
// if err != nil { | ||
// t.Fatalf("Error reading from pipe: %v", err) | ||
// } | ||
// t.Logf("captop: %v", capturedOutput.String()) | ||
|
||
// Line split stdout | ||
lines := strings.Split(capturedOutput.String(), "\n") | ||
for _, line := range lines { | ||
// Example: Check for keywords and versions | ||
if strings.Contains(line, " Golang(version") { | ||
t.Logf("line: %s", line) | ||
if !strings.Contains(line, criteriaTable["Golang"]) { | ||
t.Logf("failing: %s", line) | ||
t.Errorf("Expected version %s not found in output for keyword %s", criteriaTable["Golang"], "Golang") | ||
} | ||
} else if strings.Contains(line, "containerd(version") { | ||
t.Logf("line: %s", line) | ||
if !strings.Contains(line, criteriaTable["containerd"]) { | ||
t.Logf("failing: %s", line) | ||
t.Errorf("Expected version %s not found in output for keyword %s", criteriaTable["containerd"], "containerd") | ||
} | ||
} else if strings.Contains(line, "runc(version") { | ||
t.Logf("line: %s", line) | ||
if !strings.Contains(line, criteriaTable["runc"]) { | ||
t.Logf("failing: %s", line) | ||
t.Errorf("Expected version %s not found in output for keyword %s", criteriaTable["runc"], "runc") | ||
} | ||
} else if strings.Contains(line, "CNI plugins(version") { | ||
t.Logf("line: %s", line) | ||
if !strings.Contains(line, criteriaTable["CNI"]) { | ||
t.Logf("failing: %s", line) | ||
t.Errorf("Expected version %s not found in output for keyword %s", criteriaTable["CNI"], "CNI") | ||
} | ||
} else if strings.Contains(line, "Kubernetes(version") { | ||
t.Logf("line: %s", line) | ||
if !strings.Contains(line, criteriaTable["Kubernetes"]) { | ||
t.Logf("failing: %s", line) | ||
t.Errorf("Expected version %s not found in output for keyword %s", criteriaTable["Kubernetes"], "Kubernetes") | ||
} | ||
} | ||
} | ||
} | ||
// // Line split stdout | ||
// lines := strings.Split(capturedOutput.String(), "\n") | ||
// for _, line := range lines { | ||
// // Example: Check for keywords and versions | ||
// if strings.Contains(line, " Golang(version") { | ||
// t.Logf("line: %s", line) | ||
// if !strings.Contains(line, criteriaTable["Golang"]) { | ||
// t.Logf("failing: %s", line) | ||
// t.Errorf("Expected version %s not found in output for keyword %s", criteriaTable["Golang"], "Golang") | ||
// } | ||
// } else if strings.Contains(line, "containerd(version") { | ||
// t.Logf("line: %s", line) | ||
// if !strings.Contains(line, criteriaTable["containerd"]) { | ||
// t.Logf("failing: %s", line) | ||
// t.Errorf("Expected version %s not found in output for keyword %s", criteriaTable["containerd"], "containerd") | ||
// } | ||
// } else if strings.Contains(line, "runc(version") { | ||
// t.Logf("line: %s", line) | ||
// if !strings.Contains(line, criteriaTable["runc"]) { | ||
// t.Logf("failing: %s", line) | ||
// t.Errorf("Expected version %s not found in output for keyword %s", criteriaTable["runc"], "runc") | ||
// } | ||
// } else if strings.Contains(line, "CNI plugins(version") { | ||
// t.Logf("line: %s", line) | ||
// if !strings.Contains(line, criteriaTable["CNI"]) { | ||
// t.Logf("failing: %s", line) | ||
// t.Errorf("Expected version %s not found in output for keyword %s", criteriaTable["CNI"], "CNI") | ||
// } | ||
// } else if strings.Contains(line, "Kubernetes(version") { | ||
// t.Logf("line: %s", line) | ||
// if !strings.Contains(line, criteriaTable["Kubernetes"]) { | ||
// t.Logf("failing: %s", line) | ||
// t.Errorf("Expected version %s not found in output for keyword %s", criteriaTable["Kubernetes"], "Kubernetes") | ||
// } | ||
// } | ||
// } | ||
// } |