...

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

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

     1  package integration_test
     2  
     3  import (
     4  	"github.com/udacity/graphb"
     5  
     6  	"edge-infra.dev/pkg/edge/api/graph/model"
     7  	sqlquery "edge-infra.dev/pkg/edge/api/sql"
     8  	"edge-infra.dev/test/framework/integration"
     9  )
    10  
    11  var (
    12  	edgeInfra                  = "store-test"
    13  	edgeInfraVersion           = "0.20"
    14  	compatibleArtifact         = "edge-os-test"
    15  	compatibleArtifactVersionA = "1.0"
    16  	compatibleArtifactVersionB = "2.0"
    17  )
    18  
    19  func (s *Suite) TestAddArtifactCompatibility() {
    20  	integration.SkipIf(s.Framework)
    21  	var response struct{ AddArtifactCompatibility bool }
    22  	_, err := s.DB.Exec(sqlquery.AddCurrentVersionToAvailableArtifacts, edgeInfra, edgeInfraVersion, "0", "20", "0")
    23  	s.NoError(err)
    24  	compA := model.ArtifactInput{Name: compatibleArtifact, Version: compatibleArtifactVersionA}
    25  	mutation := addOrDeleteAvailableArtifactCompatibilityMutation("addArtifactCompatibility", edgeInfra, edgeInfraVersion, 1, []*model.ArtifactInput{&compA})
    26  	err = ResolverClient.Post(mutation, &response)
    27  	s.NoErrorf(err, "error resolving compatibility mutation")
    28  	s.True(response.AddArtifactCompatibility)
    29  	row := s.DB.QueryRow(sqlquery.GetArtifactVersionsAndCompatibility, edgeInfra, edgeInfraVersion)
    30  	var aName, aVersion, compatibleArtifactName, compatibleArtifactVersion string
    31  	var artifactNthIndex int
    32  	s.NoError(row.Scan(&aName, &aVersion, &artifactNthIndex, &compatibleArtifactName, &compatibleArtifactVersion))
    33  	s.Equal(edgeInfra, aName)
    34  	s.Equal(edgeInfraVersion, aVersion)
    35  	s.Equal(1, artifactNthIndex)
    36  	s.Equal(compatibleArtifact, compatibleArtifactName)
    37  	s.Equal(compatibleArtifactVersionA, compatibleArtifactVersion)
    38  	_, err = s.DB.Exec(sqlquery.DeleteArtifactCompatibility, aName, aVersion, compatibleArtifactName, compatibleArtifactVersion)
    39  	s.NoError(err)
    40  }
    41  
    42  func (s *Suite) TestDeleteArtifactCompatibility() {
    43  	integration.SkipIf(s.Framework)
    44  	var response struct{ DeleteArtifactCompatibility bool }
    45  	_, err := s.DB.Exec(sqlquery.AddCurrentVersionToAvailableArtifacts, edgeInfra, edgeInfraVersion, "0", "20", "0")
    46  	s.NoError(err)
    47  	_, err = s.DB.Exec(sqlquery.AddArtifactCompatibility, edgeInfra, edgeInfraVersion, 1, compatibleArtifact, compatibleArtifactVersionB)
    48  	s.NoError(err)
    49  	compB := model.ArtifactInput{Name: compatibleArtifact, Version: compatibleArtifactVersionB}
    50  	mutation := addOrDeleteAvailableArtifactCompatibilityMutation("deleteArtifactCompatibility", edgeInfra, edgeInfraVersion, 1, []*model.ArtifactInput{&compB})
    51  	err = ResolverClient.Post(mutation, &response)
    52  	s.NoErrorf(err, "error resolving compatibility mutation")
    53  	s.True(response.DeleteArtifactCompatibility)
    54  	s.NoError(err)
    55  }
    56  
    57  func (s *Suite) TestGetArtifactVersionCompatibility() {
    58  	integration.SkipIf(s.Framework)
    59  	var response struct{ GetArtifactVersionCompatibility *model.ArtifactCompatibility }
    60  	query := getArtifactCompatibilityQuery("store", "0.15")
    61  	ResolverClient.MustPost(query, &response)
    62  	s.Equal("store", response.GetArtifactVersionCompatibility.Artifact.Name)
    63  	s.Equal("0.15", response.GetArtifactVersionCompatibility.Artifact.Version)
    64  	s.Len(response.GetArtifactVersionCompatibility.CompatibleArtifacts, 2)
    65  }
    66  
    67  func (s *Suite) TestCheckVersionSupport() {
    68  	integration.SkipIf(s.Framework)
    69  	var response struct{ CheckVersionSupport bool }
    70  	query := checkVersionSupportedQuery("store", "0.13")
    71  	ResolverClient.MustPost(query, &response)
    72  	s.False(response.CheckVersionSupport)
    73  }
    74  
    75  func addOrDeleteAvailableArtifactCompatibilityMutation(queryName, artifactName, artifactVersion string, nthIndex int, compatibleArtifacts []*model.ArtifactInput) string {
    76  	compatibleArtifactsArg := make([][]graphb.Argument, 0, len(compatibleArtifacts))
    77  	for _, artifact := range compatibleArtifacts {
    78  		compatibleArtifactArgument := graphb.ArgumentCustomTypeSliceElem(
    79  			graphb.ArgumentString("name", artifact.Name),
    80  			graphb.ArgumentString("version", artifact.Version),
    81  		)
    82  		compatibleArtifactsArg = append(compatibleArtifactsArg, compatibleArtifactArgument)
    83  	}
    84  	artifactArg := []graphb.Argument{
    85  		graphb.ArgumentString("name", artifactName),
    86  		graphb.ArgumentString("version", artifactVersion),
    87  	}
    88  	artifactArgs := graphb.ArgumentCustomType("artifact", artifactArg...)
    89  	nthIndexArg := graphb.ArgumentInt("nthIndex", nthIndex)
    90  	compArtArg := graphb.ArgumentCustomTypeSlice("compatibleArtifacts", compatibleArtifactsArg...)
    91  	args := graphb.ArgumentCustomType("artifactCompatibility", artifactArgs, nthIndexArg, compArtArg)
    92  	return MustParse(graphb.Query{
    93  		Type: graphb.TypeMutation,
    94  		Fields: []*graphb.Field{
    95  			{
    96  				Name:      queryName,
    97  				Arguments: []graphb.Argument{args},
    98  			},
    99  		},
   100  	})
   101  }
   102  
   103  func getArtifactCompatibilityQuery(artifactName, artifactVersion string) string {
   104  	return MustParse(graphb.Query{
   105  		Type: graphb.TypeQuery,
   106  		Fields: []*graphb.Field{
   107  			{
   108  				Name: "getArtifactVersionCompatibility",
   109  				Arguments: []graphb.Argument{
   110  					graphb.ArgumentString("artifactName", artifactName),
   111  					graphb.ArgumentString("artifactVersion", artifactVersion),
   112  				},
   113  				Fields: []*graphb.Field{
   114  					{
   115  						Name: "artifact",
   116  						Fields: []*graphb.Field{
   117  							{
   118  								Name: "name",
   119  							},
   120  							{
   121  								Name: "version",
   122  							},
   123  						},
   124  					},
   125  					graphb.NewField("nthIndex"),
   126  					graphb.NewField("compatibleArtifacts", graphb.OfFields("name", "version")),
   127  				},
   128  			},
   129  		},
   130  	})
   131  }
   132  
   133  func checkVersionSupportedQuery(artifactName, artifactVersion string) string {
   134  	return MustParse(graphb.Query{
   135  		Type: graphb.TypeQuery,
   136  		Fields: []*graphb.Field{
   137  			{
   138  				Name: "checkVersionSupport",
   139  				Arguments: []graphb.Argument{
   140  					graphb.ArgumentString("artifactName", artifactName),
   141  					graphb.ArgumentString("artifactVersion", artifactVersion),
   142  				},
   143  			},
   144  		},
   145  	})
   146  }
   147  

View as plain text