...

Source file src/edge-infra.dev/pkg/edge/api/graph/integration/bootstrap_queries.resolvers_test.go

Documentation: edge-infra.dev/pkg/edge/api/graph/integration

     1  package integration_test
     2  
     3  import (
     4  	"encoding/json"
     5  	"strings"
     6  
     7  	sourceApi "github.com/fluxcd/source-controller/api/v1"
     8  	"github.com/udacity/graphb"
     9  
    10  	"edge-infra.dev/pkg/edge/api/graph/model"
    11  	"edge-infra.dev/test/framework/integration"
    12  )
    13  
    14  const (
    15  	testBootstrapClusterID         = "3396a52c-6a22-4049-9593-5a63b596a205"
    16  	testBootstrapInactiveClusterID = "3396a52c-6a22-4049-9593-5a63b596a201"
    17  )
    18  
    19  func (s *Suite) TestBootstrapActiveCluster() {
    20  	integration.SkipIf(s.Framework)
    21  	var response struct{ BootstrapCluster *model.BootstrapResponse }
    22  	force := true
    23  	mutation := bootstrapClusterMutation(&model.BootstrapPayload{
    24  		ClusterEdgeID: "3396a52c-6a22-4049-9593-5a63b596a200",
    25  		Force:         &force,
    26  	})
    27  	ResolverClient.MustPost(mutation, &response)
    28  	s.NotNil(response.BootstrapCluster)
    29  	s.NotEmpty(response.BootstrapCluster.ProjectID)
    30  	s.NotEmpty(response.BootstrapCluster.Secrets)
    31  	s.NotEmpty(response.BootstrapCluster.FluxConfig)
    32  	s.Equal(1, len(response.BootstrapCluster.FluxConfig.FluxKustomize))
    33  	s.Equal(4, len(response.BootstrapCluster.Secrets))
    34  }
    35  
    36  func (s *Suite) TestBootstrapInactiveCluster() {
    37  	integration.SkipIf(s.Framework)
    38  	var response struct{ BootstrapCluster *model.BootstrapResponse }
    39  	mutation := bootstrapClusterMutation(&model.BootstrapPayload{
    40  		ClusterEdgeID: testBootstrapInactiveClusterID, // inactive cluster
    41  	})
    42  	ResolverClient.MustPost(mutation, &response)
    43  	s.NotNil(response.BootstrapCluster)
    44  	s.NotEmpty(response.BootstrapCluster.ProjectID)
    45  	s.NotEmpty(response.BootstrapCluster.Secrets)
    46  	s.NotEmpty(response.BootstrapCluster.FluxConfig)
    47  	s.Equal(1, len(response.BootstrapCluster.FluxConfig.FluxKustomize))
    48  	s.Equal(4, len(response.BootstrapCluster.Secrets))
    49  }
    50  
    51  func (s *Suite) TestBootstrapCluster() {
    52  	integration.SkipIf(s.Framework)
    53  	var response struct{ BootstrapCluster *model.BootstrapResponse }
    54  	force := true
    55  	mutation := bootstrapClusterMutation(&model.BootstrapPayload{
    56  		ClusterEdgeID: testBootstrapClusterID,
    57  		Force:         &force,
    58  	})
    59  	ResolverClient.MustPost(mutation, &response)
    60  	s.NotNil(response.BootstrapCluster)
    61  	s.NotEmpty(response.BootstrapCluster.ProjectID)
    62  	s.NotEmpty(response.BootstrapCluster.Secrets)
    63  	s.NotEmpty(response.BootstrapCluster.FluxConfig)
    64  	s.Equal(1, len(response.BootstrapCluster.FluxConfig.FluxKustomize))
    65  
    66  	bucket := &sourceApi.Bucket{}
    67  	err := json.Unmarshal([]byte(response.BootstrapCluster.FluxConfig.FluxBucket[0]), bucket)
    68  	s.NoError(err)
    69  	s.Equal("edge-bucket", bucket.Name)
    70  	s.True(strings.Contains(*bucket.Spec.Ignore, "3396a52c-6a22-4049-9593-5a63b596a205"))
    71  	s.Equal(4, len(response.BootstrapCluster.Secrets))
    72  }
    73  
    74  func (s *Suite) TestBootstrapClusterCaHash() {
    75  	integration.SkipIf(s.Framework)
    76  	var response struct{ BootstrapCluster *model.BootstrapResponse }
    77  	force := true
    78  	clusterCaHash := "658ef40b47f068cdbc8e8a069d18e72df1a37c38f26890e7e2543decc242459e"
    79  	mutation := bootstrapClusterMutation(&model.BootstrapPayload{
    80  		ClusterEdgeID: "3396a52c-6a22-4049-9593-5a63b596a200",
    81  		Force:         &force,
    82  		ClusterCaHash: &clusterCaHash,
    83  	})
    84  	ResolverClient.MustPost(mutation, &response)
    85  	s.NotNil(response.BootstrapCluster)
    86  	s.NotEmpty(response.BootstrapCluster.ProjectID)
    87  	s.NotEmpty(response.BootstrapCluster.Secrets)
    88  	s.NotEmpty(response.BootstrapCluster.FluxConfig)
    89  	s.Equal(1, len(response.BootstrapCluster.FluxConfig.FluxKustomize))
    90  	s.Equal(4, len(response.BootstrapCluster.Secrets))
    91  }
    92  
    93  func bootstrapClusterMutation(payload *model.BootstrapPayload) string {
    94  	payloadArgs := []graphb.Argument{
    95  		graphb.ArgumentString("clusterEdgeId", payload.ClusterEdgeID),
    96  	}
    97  	if payload.Force != nil {
    98  		payloadArgs = append(payloadArgs, graphb.ArgumentBool("force", *payload.Force))
    99  	}
   100  
   101  	if payload.ClusterCaHash != nil {
   102  		payloadArgs = append(payloadArgs, graphb.ArgumentString("clusterCaHash", *payload.ClusterCaHash))
   103  	}
   104  
   105  	return MustParse(graphb.Query{
   106  		Type: graphb.TypeMutation,
   107  		Fields: []*graphb.Field{
   108  			{
   109  				Name:      "bootstrapCluster",
   110  				Arguments: []graphb.Argument{graphb.ArgumentCustomType("payload", payloadArgs...)},
   111  				Fields: []*graphb.Field{
   112  					{
   113  						Name: "projectId",
   114  					},
   115  					{
   116  						Name: "secrets",
   117  					},
   118  					{
   119  						Name: "fluxConfig",
   120  						Fields: []*graphb.Field{
   121  							{
   122  								Name: "fluxBucket",
   123  							},
   124  							{
   125  								Name: "fluxKustomize",
   126  							},
   127  						},
   128  					},
   129  				},
   130  			},
   131  		},
   132  	})
   133  }
   134  

View as plain text