...

Source file src/edge-infra.dev/pkg/edge/api/graph/integration/terminal_disks_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  	"edge-infra.dev/pkg/edge/api/services"
     8  	"edge-infra.dev/pkg/edge/api/utils"
     9  	"edge-infra.dev/test/framework/integration"
    10  )
    11  
    12  func (s *Suite) TestGetTerminalWithDisks() {
    13  	integration.SkipIf(s.Framework)
    14  
    15  	var response struct{ Terminal *model.Terminal }
    16  	terminalID := "6246c60b-9c8b-4510-b3bb-fb8fa1f9fbad"
    17  	query := getTerminalWithDisksQuery(terminalID)
    18  	err = ResolverClient.Post(query, &response)
    19  
    20  	s.NoErrorf(err, "error posting to resolver client")
    21  	s.NotEmptyf(response.Terminal, "returned terminal empty")
    22  	s.Equalf(terminalID, response.Terminal.TerminalID, "incorrect terminalId")
    23  	s.NotEmptyf(response.Terminal.Disks, "empty disks")
    24  	disk := response.Terminal.Disks[0]
    25  	s.NotNilf(disk, "nil disk")
    26  	expectedDisk := &model.TerminalDisk{
    27  		TerminalDiskID: "9dca53a3-7527-44d9-a7d4-fb704379c7a0",
    28  		TerminalID:     terminalID,
    29  		IncludeDisk:    true,
    30  		ExpectEmpty:    true,
    31  		DevicePath:     "/dev/sda",
    32  		UsePart:        true,
    33  	}
    34  	s.Equalf(expectedDisk, disk, "incorrect disk")
    35  }
    36  
    37  func (s *Suite) TestCreateTerminalDisk() {
    38  	integration.SkipIf(s.Framework)
    39  
    40  	var response struct{ CreateTerminalDisk model.TerminalDisk }
    41  	terminalID := "42742ecf-55fa-467a-a3b2-174015a8109f"
    42  	includeDisk := false
    43  	expectEmpty := false
    44  	devicePath := "/dev/sdg"
    45  	usePart := true
    46  	newDisk := model.TerminalDiskCreateInput{
    47  		IncludeDisk: includeDisk,
    48  		ExpectEmpty: expectEmpty,
    49  		DevicePath:  devicePath,
    50  		UsePart:     usePart,
    51  	}
    52  	mutation := createTerminalDiskMutation(terminalID, newDisk)
    53  	err := ResolverClient.Post(mutation, &response)
    54  	s.NoErrorf(err, "error posting to resolver client")
    55  	s.Equalf(terminalID, response.CreateTerminalDisk.TerminalID, "incorrect terminalId")
    56  	s.Equalf(includeDisk, response.CreateTerminalDisk.IncludeDisk, "incorrect includeDisk")
    57  	s.Equalf(expectEmpty, response.CreateTerminalDisk.ExpectEmpty, "incorrect expectEmpty")
    58  	s.Equalf(devicePath, response.CreateTerminalDisk.DevicePath, "incorrect devicePath")
    59  	s.Equalf(usePart, response.CreateTerminalDisk.UsePart, "incorrect usePart")
    60  }
    61  
    62  func (s *Suite) TestCreateTerminalDiskDuplicateDevicePath() {
    63  	integration.SkipIf(s.Framework)
    64  
    65  	var response struct{ CreateTerminalDisk model.TerminalDisk }
    66  	terminalID := "6246c60b-9c8b-4510-b3bb-fb8fa1f9fbad"
    67  	includeDisk := true
    68  	expectEmpty := true
    69  	devicePath := "/dev/sda"
    70  	usePart := true
    71  	newDisk := model.TerminalDiskCreateInput{
    72  		IncludeDisk: includeDisk,
    73  		ExpectEmpty: expectEmpty,
    74  		DevicePath:  devicePath,
    75  		UsePart:     usePart,
    76  	}
    77  	mutation := createTerminalDiskMutation(terminalID, newDisk)
    78  	err := ResolverClient.Post(mutation, &response)
    79  	s.ErrorContains(err, services.ErrDuplicateTerminalDiskDevicePaths.Error())
    80  }
    81  
    82  func (s *Suite) TestUpdateTerminalDisk() {
    83  	integration.SkipIf(s.Framework)
    84  
    85  	var response struct{ UpdateTerminalDisk model.TerminalDisk }
    86  	terminalID := "42742ecf-55fa-467a-a3b2-174015a8109f"
    87  	diskID := "ffd5d566-0569-4c8e-8fec-a283898fb487"
    88  	includeDisk := false
    89  	expectEmpty := true
    90  	devicePath := "/dev/sde"
    91  	usePart := true
    92  	disk := model.TerminalDiskIDInput{
    93  		TerminalDiskID: diskID,
    94  		TerminalDiskValues: &model.TerminalDiskUpdateInput{
    95  			IncludeDisk: &includeDisk,
    96  			ExpectEmpty: &expectEmpty,
    97  			DevicePath:  &devicePath,
    98  			UsePart:     &usePart,
    99  		},
   100  	}
   101  	mutation := updateTerminalDiskMutation(disk)
   102  	err := ResolverClient.Post(mutation, &response)
   103  	s.NoErrorf(err, "error posting to resolver client")
   104  	expectedDisk := model.TerminalDisk{
   105  		TerminalDiskID: diskID,
   106  		TerminalID:     terminalID,
   107  		IncludeDisk:    includeDisk,
   108  		ExpectEmpty:    expectEmpty,
   109  		DevicePath:     devicePath,
   110  		UsePart:        usePart,
   111  	}
   112  	s.Equalf(expectedDisk, response.UpdateTerminalDisk, "incorrect disk")
   113  }
   114  
   115  func (s *Suite) TestUpdateTerminalDiskDuplicateDevicePath() {
   116  	integration.SkipIf(s.Framework)
   117  
   118  	var response struct{ UpdateTerminalDisk model.TerminalDisk }
   119  	diskID := "9dca53a3-7527-44d9-a7d4-fb704379c7a0"
   120  	includeDisk := true
   121  	expectEmpty := true
   122  	devicePath := "/dev/sda"
   123  	usePart := true
   124  	disk := model.TerminalDiskIDInput{
   125  		TerminalDiskID: diskID,
   126  		TerminalDiskValues: &model.TerminalDiskUpdateInput{
   127  			IncludeDisk: &includeDisk,
   128  			ExpectEmpty: &expectEmpty,
   129  			DevicePath:  &devicePath,
   130  			UsePart:     &usePart,
   131  		},
   132  	}
   133  	mutation := updateTerminalDiskMutation(disk)
   134  	err := ResolverClient.Post(mutation, &response)
   135  	s.ErrorContains(err, services.ErrDuplicateTerminalDiskDevicePaths.Error())
   136  }
   137  
   138  func (s *Suite) TestDeleteTerminalDisk() {
   139  	integration.SkipIf(s.Framework)
   140  
   141  	var response struct{ DeleteTerminalDisk bool }
   142  	diskID := "45b47b4e-dae2-4bfb-a371-e1750517cf64"
   143  	mutation := deleteTerminalDiskMutation(diskID)
   144  	err := ResolverClient.Post(mutation, &response)
   145  	s.NoErrorf(err, "error posting to resolver client")
   146  	s.Truef(response.DeleteTerminalDisk, "delete returned false")
   147  }
   148  
   149  func getTerminalWithDisksQuery(terminalID string) string {
   150  	return MustParse(graphb.Query{
   151  		Type: graphb.TypeQuery,
   152  		Fields: []*graphb.Field{
   153  			{
   154  				Name: "terminal",
   155  				Arguments: []graphb.Argument{
   156  					graphb.ArgumentString("terminalId", terminalID),
   157  				},
   158  				Fields: terminalFieldsWithDisks,
   159  			},
   160  		},
   161  	})
   162  }
   163  
   164  func createTerminalDiskMutation(terminalID string, newDisk model.TerminalDiskCreateInput) string {
   165  	newDiskArg := graphb.ArgumentCustomTypeSliceElem(
   166  		graphb.ArgumentBool("includeDisk", newDisk.IncludeDisk),
   167  		graphb.ArgumentBool("expectEmpty", newDisk.ExpectEmpty),
   168  		graphb.ArgumentString("devicePath", newDisk.DevicePath),
   169  		graphb.ArgumentBool("usePart", newDisk.UsePart),
   170  	)
   171  	return MustParse(graphb.Query{
   172  		Type: graphb.TypeMutation,
   173  		Fields: []*graphb.Field{
   174  			{
   175  				Name: "createTerminalDisk",
   176  				Arguments: []graphb.Argument{
   177  					graphb.ArgumentString("terminalId", terminalID),
   178  					graphb.ArgumentCustomType("newTerminalDisk", newDiskArg...),
   179  				},
   180  				Fields: terminalDiskFields,
   181  			},
   182  		},
   183  	})
   184  }
   185  
   186  func updateTerminalDiskMutation(terminalDisk model.TerminalDiskIDInput) string {
   187  	diskValuesArg := graphb.ArgumentCustomTypeSliceElem(
   188  		graphb.ArgumentBool("includeDisk", utils.ConvertToBool(terminalDisk.TerminalDiskValues.IncludeDisk)),
   189  		graphb.ArgumentBool("expectEmpty", utils.ConvertToBool(terminalDisk.TerminalDiskValues.ExpectEmpty)),
   190  		graphb.ArgumentString("devicePath", utils.ConvertToString(terminalDisk.TerminalDiskValues.DevicePath)),
   191  		graphb.ArgumentBool("usePart", utils.ConvertToBool(terminalDisk.TerminalDiskValues.UsePart)),
   192  	)
   193  	return MustParse(graphb.Query{
   194  		Type: graphb.TypeMutation,
   195  		Fields: []*graphb.Field{
   196  			{
   197  				Name: "updateTerminalDisk",
   198  				Arguments: []graphb.Argument{
   199  					graphb.ArgumentCustomType("terminalDisk",
   200  						graphb.ArgumentString("terminalDiskId", terminalDisk.TerminalDiskID),
   201  						graphb.ArgumentCustomType("terminalDiskValues", diskValuesArg...),
   202  					),
   203  				},
   204  				Fields: terminalDiskFields,
   205  			},
   206  		},
   207  	})
   208  }
   209  
   210  func deleteTerminalDiskMutation(terminalDiskID string) string {
   211  	return MustParse(graphb.Query{
   212  		Type: graphb.TypeMutation,
   213  		Fields: []*graphb.Field{
   214  			{
   215  				Name: "deleteTerminalDisk",
   216  				Arguments: []graphb.Argument{
   217  					graphb.ArgumentString("terminalDiskId", terminalDiskID),
   218  				},
   219  			},
   220  		},
   221  	})
   222  }
   223  
   224  var terminalFieldsWithDisks = []*graphb.Field{
   225  	{
   226  		Name: "terminalId",
   227  	},
   228  	{
   229  		Name:   "disks",
   230  		Fields: terminalDiskFields,
   231  	},
   232  }
   233  
   234  var terminalDiskFields = []*graphb.Field{
   235  	{
   236  		Name: "terminalDiskId",
   237  	},
   238  	{
   239  		Name: "terminalId",
   240  	},
   241  	{
   242  		Name: "includeDisk",
   243  	},
   244  	{
   245  		Name: "expectEmpty",
   246  	},
   247  	{
   248  		Name: "devicePath",
   249  	},
   250  	{
   251  		Name: "usePart",
   252  	},
   253  }
   254  

View as plain text