github.com/0xPolygon/supernets2-node@v0.0.0-20230711153321-2fe574524eaa/test/scripts/cmd/dependencies/testvectors.go (about)

     1  package dependencies
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/0xPolygon/supernets2-node/log"
     7  	"github.com/spf13/afero"
     8  )
     9  
    10  // TVConfig is the configuration for the test vector updater.
    11  type TVConfig struct {
    12  	TargetDirPath string
    13  	SourceRepo    string
    14  }
    15  
    16  type testVectorUpdater struct {
    17  	fs afero.Fs
    18  
    19  	gm *githubManager
    20  
    21  	sourceRepo    string
    22  	targetDirPath string
    23  }
    24  
    25  func newTestVectorUpdater(sourceRepo, targetDirPath string) *testVectorUpdater {
    26  	aferoFs := afero.NewOsFs()
    27  
    28  	gm := newGithubManager(aferoFs, os.Getenv("UPDATE_DEPS_SSH_PK"), os.Getenv("GITHUB_TOKEN"))
    29  
    30  	return &testVectorUpdater{
    31  		fs: aferoFs,
    32  
    33  		gm: gm,
    34  
    35  		sourceRepo:    sourceRepo,
    36  		targetDirPath: targetDirPath,
    37  	}
    38  }
    39  
    40  func (tu *testVectorUpdater) update() error {
    41  	log.Infof("Cloning %q...", tu.sourceRepo)
    42  	tmpdir, err := tu.gm.cloneTargetRepo(tu.sourceRepo)
    43  	if err != nil {
    44  		return err
    45  	}
    46  
    47  	targetDirPath := getTargetPath(tu.targetDirPath)
    48  
    49  	log.Infof("Updating files %q...", tu.sourceRepo)
    50  	return updateFiles(tu.fs, tmpdir, targetDirPath)
    51  }