github.com/replit/upm@v0.0.0-20240423230255-9ce4fc3ea24c/test-suite/Lock_test.go (about)

     1  package testSuite
     2  
     3  import (
     4  	"testing"
     5  
     6  	testUtils "github.com/replit/upm/test-suite/utils"
     7  )
     8  
     9  var testLocks = map[string]bool{
    10  	"bun":            true,
    11  	"nodejs-npm":     true,
    12  	"nodejs-pnpm":    true,
    13  	"nodejs-yarn":    true,
    14  	"python3-poetry": true,
    15  }
    16  
    17  func TestLock(t *testing.T) {
    18  	for _, bt := range languageBackends {
    19  		bt.Start(t)
    20  
    21  		if !testLocks[bt.Backend.Name] {
    22  			t.Run(bt.Backend.Name, func(t *testing.T) {
    23  				t.Skip("no test")
    24  			})
    25  			continue
    26  		}
    27  
    28  		bt.Subtest(bt.Backend.Name, doLock)
    29  	}
    30  }
    31  
    32  func doLock(bt testUtils.BackendT) {
    33  	// test absence of lock file
    34  	for _, tmpl := range standardTemplates {
    35  		template := bt.Backend.Name + "/" + tmpl + "/"
    36  
    37  		bt.Subtest(tmpl, func(bt testUtils.BackendT) {
    38  			bt.AddTestFile(template+bt.Backend.Specfile, bt.Backend.Specfile)
    39  
    40  			specDeps := bt.UpmListSpecFile()
    41  
    42  			bt.UpmLock()
    43  
    44  			lockDeps := bt.UpmListLockFile()
    45  
    46  			for _, specDep := range specDeps {
    47  				found := false
    48  				for _, lockDep := range lockDeps {
    49  					if specDep.Name == lockDep.Name {
    50  						found = true
    51  						break
    52  					}
    53  				}
    54  
    55  				if !found {
    56  					bt.Fail("expected %s in lock file", specDep.Name)
    57  				}
    58  			}
    59  		})
    60  	}
    61  
    62  	// test absence of package dir
    63  	bt.Subtest(bt.Backend.Name+"/no-package-dir", func(bt testUtils.BackendT) {
    64  		bt.AddTestFile(bt.Backend.Name+"/many-deps/"+bt.Backend.Specfile, bt.Backend.Specfile)
    65  
    66  		specDeps := bt.UpmListSpecFile()
    67  
    68  		bt.UpmLock()
    69  
    70  		lockDeps := bt.UpmListLockFile()
    71  
    72  		for _, specDep := range specDeps {
    73  			found := false
    74  			for _, lockDep := range lockDeps {
    75  				if specDep.Name == lockDep.Name {
    76  					found = true
    77  					break
    78  				}
    79  			}
    80  
    81  			if !found {
    82  				bt.Fail("expected %s in lock file", specDep.Name)
    83  			}
    84  		}
    85  	})
    86  }