aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/internal/mock/vespa.go
blob: ca09a3893604f62a769908ad853b65060781ca2e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package mock

import (
	"os"
	"path/filepath"
	"testing"
)

// ApplicationPackageDir creates a mock application package directory using test helper t, returning the path to the
// "application" directory and the root directory where it was created. If java is true, create a file that indicates
// this package contains Java code. If cert is true, create an empty certificate file.
func ApplicationPackageDir(t *testing.T, java, cert bool) (string, string) {
	t.Helper()
	rootDir := t.TempDir()
	appDir := filepath.Join(rootDir, "src", "main", "application")
	if err := os.MkdirAll(appDir, 0755); err != nil {
		t.Fatal(err)
	}
	servicesXML := filepath.Join(appDir, "services.xml")
	if _, err := os.Create(servicesXML); err != nil {
		t.Fatal(err)
	}
	if java {
		if _, err := os.Create(filepath.Join(rootDir, "pom.xml")); err != nil {
			t.Fatal(err)
		}
	}
	if cert {
		securityDir := filepath.Join(appDir, "security")
		if err := os.MkdirAll(securityDir, 0755); err != nil {
			t.Fatal(err)
		}
		if _, err := os.Create(filepath.Join(securityDir, "clients.pem")); err != nil {
			t.Fatal(err)
		}
	}
	return appDir, rootDir
}