package integration_test import ( "encoding/json" "strings" sourceApi "github.com/fluxcd/source-controller/api/v1" "github.com/udacity/graphb" "edge-infra.dev/pkg/edge/api/graph/model" "edge-infra.dev/test/framework/integration" ) const ( testBootstrapClusterID = "3396a52c-6a22-4049-9593-5a63b596a205" testBootstrapInactiveClusterID = "3396a52c-6a22-4049-9593-5a63b596a201" ) func (s *Suite) TestBootstrapActiveCluster() { integration.SkipIf(s.Framework) var response struct{ BootstrapCluster *model.BootstrapResponse } force := true mutation := bootstrapClusterMutation(&model.BootstrapPayload{ ClusterEdgeID: "3396a52c-6a22-4049-9593-5a63b596a200", Force: &force, }) ResolverClient.MustPost(mutation, &response) s.NotNil(response.BootstrapCluster) s.NotEmpty(response.BootstrapCluster.ProjectID) s.NotEmpty(response.BootstrapCluster.Secrets) s.NotEmpty(response.BootstrapCluster.FluxConfig) s.Equal(1, len(response.BootstrapCluster.FluxConfig.FluxKustomize)) s.Equal(4, len(response.BootstrapCluster.Secrets)) } func (s *Suite) TestBootstrapInactiveCluster() { integration.SkipIf(s.Framework) var response struct{ BootstrapCluster *model.BootstrapResponse } mutation := bootstrapClusterMutation(&model.BootstrapPayload{ ClusterEdgeID: testBootstrapInactiveClusterID, // inactive cluster }) ResolverClient.MustPost(mutation, &response) s.NotNil(response.BootstrapCluster) s.NotEmpty(response.BootstrapCluster.ProjectID) s.NotEmpty(response.BootstrapCluster.Secrets) s.NotEmpty(response.BootstrapCluster.FluxConfig) s.Equal(1, len(response.BootstrapCluster.FluxConfig.FluxKustomize)) s.Equal(4, len(response.BootstrapCluster.Secrets)) } func (s *Suite) TestBootstrapCluster() { integration.SkipIf(s.Framework) var response struct{ BootstrapCluster *model.BootstrapResponse } force := true mutation := bootstrapClusterMutation(&model.BootstrapPayload{ ClusterEdgeID: testBootstrapClusterID, Force: &force, }) ResolverClient.MustPost(mutation, &response) s.NotNil(response.BootstrapCluster) s.NotEmpty(response.BootstrapCluster.ProjectID) s.NotEmpty(response.BootstrapCluster.Secrets) s.NotEmpty(response.BootstrapCluster.FluxConfig) s.Equal(1, len(response.BootstrapCluster.FluxConfig.FluxKustomize)) bucket := &sourceApi.Bucket{} err := json.Unmarshal([]byte(response.BootstrapCluster.FluxConfig.FluxBucket[0]), bucket) s.NoError(err) s.Equal("edge-bucket", bucket.Name) s.True(strings.Contains(*bucket.Spec.Ignore, "3396a52c-6a22-4049-9593-5a63b596a205")) s.Equal(4, len(response.BootstrapCluster.Secrets)) } func (s *Suite) TestBootstrapClusterCaHash() { integration.SkipIf(s.Framework) var response struct{ BootstrapCluster *model.BootstrapResponse } force := true clusterCaHash := "658ef40b47f068cdbc8e8a069d18e72df1a37c38f26890e7e2543decc242459e" mutation := bootstrapClusterMutation(&model.BootstrapPayload{ ClusterEdgeID: "3396a52c-6a22-4049-9593-5a63b596a200", Force: &force, ClusterCaHash: &clusterCaHash, }) ResolverClient.MustPost(mutation, &response) s.NotNil(response.BootstrapCluster) s.NotEmpty(response.BootstrapCluster.ProjectID) s.NotEmpty(response.BootstrapCluster.Secrets) s.NotEmpty(response.BootstrapCluster.FluxConfig) s.Equal(1, len(response.BootstrapCluster.FluxConfig.FluxKustomize)) s.Equal(4, len(response.BootstrapCluster.Secrets)) } func bootstrapClusterMutation(payload *model.BootstrapPayload) string { payloadArgs := []graphb.Argument{ graphb.ArgumentString("clusterEdgeId", payload.ClusterEdgeID), } if payload.Force != nil { payloadArgs = append(payloadArgs, graphb.ArgumentBool("force", *payload.Force)) } if payload.ClusterCaHash != nil { payloadArgs = append(payloadArgs, graphb.ArgumentString("clusterCaHash", *payload.ClusterCaHash)) } return MustParse(graphb.Query{ Type: graphb.TypeMutation, Fields: []*graphb.Field{ { Name: "bootstrapCluster", Arguments: []graphb.Argument{graphb.ArgumentCustomType("payload", payloadArgs...)}, Fields: []*graphb.Field{ { Name: "projectId", }, { Name: "secrets", }, { Name: "fluxConfig", Fields: []*graphb.Field{ { Name: "fluxBucket", }, { Name: "fluxKustomize", }, }, }, }, }, }, }) }