github.com/google/osv-scalibr@v0.4.1/extractor/filesystem/language/javascript/yarnlock/yarnlock_test.go (about)

     1  // Copyright 2025 Google LLC
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package yarnlock_test
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/google/osv-scalibr/extractor/filesystem/language/javascript/yarnlock"
    21  	"github.com/google/osv-scalibr/extractor/filesystem/simplefileapi"
    22  )
    23  
    24  func TestExtractor_FileRequired(t *testing.T) {
    25  	tests := []struct {
    26  		name      string
    27  		inputPath string
    28  		want      bool
    29  	}{
    30  		{
    31  			inputPath: "",
    32  			want:      false,
    33  		},
    34  		{
    35  			inputPath: "yarn.lock",
    36  			want:      true,
    37  		},
    38  		{
    39  			inputPath: "path/to/my/yarn.lock",
    40  			want:      true,
    41  		},
    42  		{
    43  			inputPath: "path/to/my/yarn.lock/file",
    44  			want:      false,
    45  		},
    46  		{
    47  			inputPath: "path/to/my/yarn.lock.file",
    48  			want:      false,
    49  		},
    50  		{
    51  			inputPath: "path.to.my.yarn.lock",
    52  			want:      false,
    53  		},
    54  		{
    55  			inputPath: "foo/node_modules/bar/yarn.lock",
    56  			want:      false,
    57  		},
    58  	}
    59  	for _, tt := range tests {
    60  		t.Run(tt.inputPath, func(t *testing.T) {
    61  			e := yarnlock.Extractor{}
    62  			got := e.FileRequired(simplefileapi.New(tt.inputPath, nil))
    63  			if got != tt.want {
    64  				t.Errorf("FileRequired(%s, FileInfo) got = %v, want %v", tt.inputPath, got, tt.want)
    65  			}
    66  		})
    67  	}
    68  }