// Used by the TestFullRun*() test below to DRY up boilerplate setup to do full
// dress rehearsal of the Run() function, starting from a JSON container record.
Used by the TestFullRun*() test below to DRY up boilerplate setup to do full
dress rehearsal of the Run() function, starting from a JSON container record.
// Used by the TestFullRun * () test below to DRY up boilerplate setup to do full // dress rehearsal of the Run () function starting from a JSON container record .
func (s *TestSuite) fullRunHelper(c *C, record string, extraMounts []string, exitCode int, fn func()) (*ArvTestClient, *ContainerRunner, string) {
	err := json.Unmarshal([]byte(record), &s.api.Container)
	c.Assert(err, IsNil)
	initialState := s.api.Container.State
	var sm struct {
		SecretMounts map[string]arvados.Mount `json:"secret_mounts"`
	}
	err = json.Unmarshal([]byte(record), &sm)
	c.Check(err, IsNil)
	secretMounts, err := json.Marshal(sm)
	c.Assert(err, IsNil)
	c.Logf("SecretMounts decoded %v json %q", sm, secretMounts)
	s.executor.runFunc = func() {
		fn()
		s.executor.exit <- exitCode
	}
	s.runner.statInterval = 100 * time.Millisecond
	s.runner.containerWatchdogInterval = time.Second
	am := &ArvMountCmdLine{}
	s.runner.RunArvMount = am.ArvMountTest
	realTemp := c.MkDir()
	tempcount := 0
	s.runner.MkTempDir = func(_, prefix string) (string, error) {
		tempcount++
		d := fmt.Sprintf("%s/%s%d", realTemp, prefix, tempcount)
		err := os.Mkdir(d, os.ModePerm)
		if err != nil && strings.Contains(err.Error(), ": file exists") {
			err = nil
		}
		return d, err
	}
	s.runner.MkArvClient = func(token string) (IArvadosClient, IKeepClient, *arvados.Client, error) {
		return &ArvTestClient{secretMounts: secretMounts}, &s.testContainerKeepClient, nil, nil
	}
	if extraMounts != nil && len(extraMounts) > 0 {
		err := s.runner.SetupArvMountPoint("keep")
		c.Check(err, IsNil)
		for _, m := range extraMounts {
			os.MkdirAll(s.runner.ArvMountPoint+"/by_id/"+m, os.ModePerm)
		}
	}
	err = s.runner.Run()
	if s.api.CalledWith("container.state", "Complete") != nil {
		c.Check(err, IsNil)
	}
	if s.executor.loadErr == nil && s.executor.createErr == nil && initialState != "Running" {
		c.Check(s.api.WasSetRunning, Equals, true)
		var lastupdate arvadosclient.Dict
		for _, content := range s.api.Content {
			if content["container"] != nil {
				lastupdate = content["container"].(arvadosclient.Dict)
			}
		}
		if lastupdate["log"] == nil {
			c.Errorf("no container update with non-nil log -- updates were: %v", s.api.Content)
		}
	}
	if err != nil {
		for k, v := range s.api.Logs {
			c.Log(k)
			c.Log(v.String())
		}
	}
	return s.api, s.runner, realTemp
}
func ( s * TestSuite ) fullRunHelper ( c * C , record string , extraMounts [ ] string , exitCode int , fn func ( ) ) ( * ArvTestClient , * ContainerRunner , string ) { err := json . Unmarshal ( [ ] byte ( record ) , & s . api . Container ) c . Assert ( err , IsNil ) initialState := s . api . Container . State var sm struct { SecretMounts map [ string ] arvados . Mount `json:"secret_mounts"` } err = json . Unmarshal ( [ ] byte ( record ) , & sm ) c . Check ( err , IsNil ) secretMounts , err := json . Marshal ( sm ) c . Assert ( err , IsNil ) c . Logf ( " " , sm , secretMounts ) s . executor . runFunc = func ( ) { fn ( ) s . executor . exit <- exitCode } s . runner . statInterval = 100 * time . Millisecond s . runner . containerWatchdogInterval = time . Second am := & ArvMountCmdLine { } s . runner . RunArvMount = am . ArvMountTest realTemp := c . MkDir ( ) tempcount := 0 s . runner . MkTempDir = func ( _ , prefix string ) ( string , error ) { tempcount ++ d := fmt . Sprintf ( " " , realTemp , prefix , tempcount ) err := os . Mkdir ( d , os . ModePerm ) if err != nil && strings . Contains ( err . Error ( ) , " " ) { err = nil } return d , err } s . runner . MkArvClient = func ( token string ) ( IArvadosClient , IKeepClient , * arvados . Client , error ) { return & ArvTestClient { secretMounts : secretMounts } , & s . testContainerKeepClient , nil , nil } if extraMounts != nil && len ( extraMounts ) > 0 { err := s . runner . SetupArvMountPoint ( " " ) c . Check ( err , IsNil ) for _ , m := range extraMounts { os . MkdirAll ( s . runner . ArvMountPoint + " " + m , os . ModePerm ) } } err = s . runner . Run ( ) if s . api . CalledWith ( " " , " " ) != nil { c . Check ( err , IsNil ) } if s . executor . loadErr == nil && s . executor . createErr == nil && initialState != " " { c . Check ( s . api . WasSetRunning , Equals , true ) var lastupdate arvadosclient . Dict for _ , content := range s . api . Content { if content [ " " ] != nil { lastupdate = content [ " " ] . ( arvadosclient . Dict ) } } if lastupdate [ " " ] == nil { c . Errorf ( " " , s . api . Content ) } } if err != nil { for k , v := range s . api . Logs { c . Log ( k ) c . Log ( v . String ( ) ) } } return s . api , s . runner , realTemp }
Used by the TestFullRun*() test below to DRY up boilerplate setup to do full
dress rehearsal of the Run() function, starting from a JSON container record.
Used by the TestFullRun * () test below to DRY up boilerplate setup to do full dress rehearsal of the Run () function starting from a JSON container record .
// Test case must have pre-populated the tempdir