diff --git a/pkg/command/cluster/clusteradd/cmd_integration_api_test.go b/pkg/command/cluster/clusteradd/cmd_integration_api_test.go new file mode 100644 index 0000000000..bfca30e54c --- /dev/null +++ b/pkg/command/cluster/clusteradd/cmd_integration_api_test.go @@ -0,0 +1,122 @@ +// Copyright (C) 2024 ScyllaDB + +//go:build all || api_integration +// +build all api_integration + +package clusteradd + +import ( + "bytes" + "context" + "fmt" + "os/exec" + "strings" + "testing" + + "github.com/scylladb/scylla-manager/v3/pkg/managerclient" + "github.com/scylladb/scylla-manager/v3/swagger/gen/scylla-manager/models" +) + +const ( + authToken = "token" + clusterIntroHost = "192.168.200.11" + testUsername = "cassandra" + testPass = "cassandra" +) + +var ( + _true = true + _false = false +) + +func TestSctoolClusterAddIntegrationAPITest(t *testing.T) { + for _, tc := range []struct { + name string + args []string + expectedCluster *models.Cluster + }{ + { + name: "create cluster, default TLS enablement", + args: []string{"cluster", "add", "--auth-token", authToken, "--host", clusterIntroHost, + "--password", testPass, "--username", testUsername}, + expectedCluster: &models.Cluster{ + ForceTLSDisabled: &_false, + ForceNonSslPort: &_false, + Name: "", + Port: 0, + }, + }, + { + name: "create cluster, force TLS enabled", + args: []string{"cluster", "add", "--auth-token", authToken, "--host", clusterIntroHost, + "--password", testPass, "--username", testUsername, "--force-tls-disabled", "false", + "--force-non-ssl-port", "true"}, + expectedCluster: &models.Cluster{ + ForceTLSDisabled: &_false, + ForceNonSslPort: &_true, + Name: "", + Port: 0, + }, + }, + { + name: "create cluster, force TLS disabled", + args: []string{"cluster", "add", "--auth-token", authToken, "--host", clusterIntroHost, + "--password", testPass, "--username", testUsername, "--force-tls-disabled", "true", + "--force-non-ssl-port", "false"}, + expectedCluster: &models.Cluster{ + ForceTLSDisabled: &_true, + ForceNonSslPort: &_false, + Name: "", + Port: 0, + }, + }, + } { + t.Run(tc.name, func(t *testing.T) { + // given + client, err := managerclient.NewClient("http://localhost:5080/api/v1") + if err != nil { + t.Fatalf("Unable to create managerclient to consume managet HTTP API, err = {%v}", err) + } + cmd := exec.Command("./sctool.api-tests", tc.args...) + var stderr bytes.Buffer + cmd.Stderr = &stderr + cmd.Dir = "/scylla-manager" + + // when + output, err := cmd.Output() + fmt.Println(string(output)) + if err != nil { + t.Fatalf("Unable to create cluster with sctool cluster add, err = {%v}, stderr = {%v}", err, stderr.String()) + } + clusterID := strings.Split(string(output), "\n")[0] + + defer func() { + if err != client.DeleteCluster(context.Background(), clusterID) { + t.Logf("Failed to delete cluster, err = {%v}", err) + } + }() + + // then + c, err := client.GetCluster(context.Background(), clusterID) + if err != nil { + t.Fatalf("Unable to retrieve cluster data using managerclient, err = {%v}", err) + } + + if c.ID != clusterID { + t.Fatalf("ClusterID mismatch {%v} != {%v}, output={%v}", c.ID, clusterID, string(output)) + } + if *c.ForceTLSDisabled != *tc.expectedCluster.ForceTLSDisabled { + t.Fatalf("ForceTLSDisabled mismatch {%v} != {%v}, output={%v}", *c.ForceTLSDisabled, + *tc.expectedCluster.ForceTLSDisabled, string(output)) + } + if *c.ForceNonSslPort != *tc.expectedCluster.ForceNonSslPort { + t.Fatalf("ForceNonSslPort mismatch {%v} != {%v}, output={%v}", *c.ForceNonSslPort, + *tc.expectedCluster.ForceNonSslPort, string(output)) + } + if c.Port != tc.expectedCluster.Port { + t.Fatalf("Port mismatch {%v} != {%v}, output={%v}", c.Port, tc.expectedCluster.Port, string(output)) + } + }) + } + +} diff --git a/pkg/command/cluster/clusterupdate/cmd_integration_api_test.go b/pkg/command/cluster/clusterupdate/cmd_integration_api_test.go new file mode 100644 index 0000000000..8327d1a9c7 --- /dev/null +++ b/pkg/command/cluster/clusterupdate/cmd_integration_api_test.go @@ -0,0 +1,123 @@ +// Copyright (C) 2024 ScyllaDB + +//go:build all || api_integration +// +build all api_integration + +package clusterupdate + +import ( + "bytes" + "context" + "os/exec" + "testing" + + "github.com/scylladb/scylla-manager/v3/pkg/managerclient" + "github.com/scylladb/scylla-manager/v3/swagger/gen/scylla-manager/models" +) + +const ( + authToken = "token" + clusterIntroHost = "192.168.200.11" + testUsername = "cassandra" + testPass = "cassandra" +) + +var ( + _true = true + _false = false +) + +func TestSctoolClusterUpdateIntegrationAPITest(t *testing.T) { + for _, tc := range []struct { + name string + args []string + expectedCluster *models.Cluster + }{ + { + name: "update cluster, no-changes", + args: []string{"cluster", "update", "--auth-token", authToken}, + expectedCluster: &models.Cluster{ + ForceTLSDisabled: &_true, + ForceNonSslPort: &_false, + }, + }, + { + name: "update cluster, force TLS enabled", + args: []string{"cluster", "update", "--force-non-ssl-port", "true"}, + expectedCluster: &models.Cluster{ + ForceTLSDisabled: &_true, + ForceNonSslPort: &_true, + }, + }, + { + name: "update cluster, force TLS disabled", + args: []string{"cluster", "update", "--force-tls-disabled", "false"}, + expectedCluster: &models.Cluster{ + ForceTLSDisabled: &_false, + ForceNonSslPort: &_false, + }, + }, + { + name: "update cluster, clean TLS flag", + args: []string{"cluster", "update", "--force-tls-disabled", "false", "--force-non-ssl-port", "true"}, + expectedCluster: &models.Cluster{ + ForceTLSDisabled: &_false, + ForceNonSslPort: &_true, + }, + }, + } { + t.Run(tc.name, func(t *testing.T) { + // given + client, err := managerclient.NewClient("http://localhost:5080/api/v1") + if err != nil { + t.Fatalf("Unable to create managerclient to consume managet HTTP API, err = {%v}", err) + } + clusterID, err := client.CreateCluster(context.Background(), &models.Cluster{ + AuthToken: authToken, + Host: clusterIntroHost, + Password: testPass, + Username: testUsername, + ForceTLSDisabled: &_true, + }) + if err != nil { + t.Fatalf("Unable to create cluster for further updates, err = {%v}", err) + } + + cmd := exec.Command("./sctool.api-tests", append([]string{"--cluster", clusterID}, tc.args...)...) + var stderr bytes.Buffer + cmd.Stderr = &stderr + cmd.Dir = "/scylla-manager" + + // when + output, err := cmd.Output() + if err != nil { + t.Fatalf("Unable to update cluster with sctool cluster update, err = {%v}, stderr = {%v}", err, stderr.String()) + } + + defer func() { + if err != client.DeleteCluster(context.Background(), clusterID) { + t.Logf("Failed to delete cluster, err = {%v}", err) + } + }() + + // then + c, err := client.GetCluster(context.Background(), clusterID) + if err != nil { + t.Fatalf("Unable to retrieve cluster data using managerclient, err = {%v}", err) + } + + if c.ID != clusterID { + t.Fatalf("ClusterID mismatch {%v} != {%v}, output={%v}", c.ID, clusterID, string(output)) + } + if *c.ForceTLSDisabled != *tc.expectedCluster.ForceTLSDisabled { + t.Fatalf("ForceTLSDisabled mismatch {%v} != {%v}, output={%v}", *c.ForceTLSDisabled, + *tc.expectedCluster.ForceTLSDisabled, string(output)) + } + if *c.ForceNonSslPort != *tc.expectedCluster.ForceNonSslPort { + t.Fatalf("ForceNonSslPort mismatch {%v} != {%v}, output={%v}", *c.ForceNonSslPort, + *tc.expectedCluster.ForceNonSslPort, string(output)) + } + }) + } + +}