Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modification in bats.yaml #35136

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

anushkamittal20
Copy link
Contributor

@anushkamittal20 anushkamittal20 commented Nov 25, 2024

Adds a more detailed bats package to match upstream

Signed-off-by: anushkamittal20 <[email protected]>
Signed-off-by: anushkamittal20 <[email protected]>
@anushkamittal20 anushkamittal20 marked this pull request as ready for review November 25, 2024 15:11
bats.yaml Outdated Show resolved Hide resolved
Signed-off-by: anushkamittal20 <[email protected]>
@octo-sts octo-sts bot added the bincapz/pass bincapz/pass Bincapz (aka. malcontent) scan didn't detect any CRITICALs on the scanned packages. label Nov 26, 2024
kranurag7
kranurag7 previously approved these changes Nov 26, 2024
bats.yaml Outdated Show resolved Hide resolved
bats.yaml Show resolved Hide resolved
- runs: |
mkdir -p "${{targets.contextdir}}/opt/bats/"
find . -maxdepth 1 -not -name '.' -not -name 'melange-out' -not -name '*.tmp' -not -name '*.log' \
-exec mv {} "${{targets.contextdir}}/opt/bats/" \;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it intended that we move over everything?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey RJ, thanks for the review. The reason we needed to add all of this was to match the upstream image. https://github.com/bats-core/bats-core/blob/master/Dockerfile where the entire repo is shifted and the link that I created above is also created.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, could we remove the .git folder? And anything else it may not actually be using at runtime?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I compared the dir in my image:

bash-5.2$ ls /opt/bats
AUTHORS                       docker                        man
Dockerfile                    docker-compose.override.dist  package.json
LICENSE.md                    docker-compose.yml            shellcheck.sh
README.md                     docs                          test
SECURITY.md                   install.sh                    uninstall.sh
bin                           lib
contrib                       libexec

vs upstream

/code # ls /opt/bats
AUTHORS                       bin                           docs                          package.json
Dockerfile                    contrib                       install.sh                    shellcheck.sh
LICENSE.md                    docker                        lib                           test
README.md                     docker-compose.override.dist  libexec                       uninstall.sh
SECURITY.md                   docker-compose.yml            man

both are the same

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I explicitly look at removing items?

Signed-off-by: anushkamittal20 <[email protected]>
Signed-off-by: anushkamittal20 <[email protected]>
Signed-off-by: anushkamittal20 <[email protected]>
Signed-off-by: anushkamittal20 <[email protected]>
./install.sh "${{targets.contextdir}}/usr"
./install.sh "${{targets.contextdir}}/usr"
mkdir -p "${{targets.contextdir}}/tmp/"
cp -r ./docker "${{targets.contextdir}}/tmp/docker"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/bats-core/bats-core/blob/89a7fae3b651d5c2f42a3874ec32e821014814eb/docker/install_libs.sh#L32 I saw that it downloads the files from their own repositories like https://github.com/bats-core/bats-support, so creating a separate packages for them like support, file, assert and detik would be great cuz in that case it'd be easier to keep these things in sync when there is a new version come up, but I'm not certain though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean like subpackages or completely new packages?

@@ -1,24 +1,22 @@
package:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writing some tests would be great here:

for example:
cat < example.sh
#!/bin/bash

Function to add two numbers

add_numbers() {
echo $(( $1 + $2 ))
}

Function to check if a file exists

file_exists() {
if [[ -f "$1" ]]; then
echo "true"
else
echo "false"
fi
}

Function to check if a string contains another string

string_contains() {
if [[ "$1" == "$2" ]]; then
echo "true"
else
echo "false"
fi
}
EOF

cat <
#!/usr/bin/env bats

Load the script to test

load_file() {
source "./example.sh"
}

setup() {
# This runs before every test
load_file
}

teardown() {
# This runs after every test
rm -f testfile.txt
}

@test "add_numbers should correctly add two numbers" {
run add_numbers 3 5
[ "$status" -eq 0 ]
[ "$output" -eq 8 ]
}

@test "file_exists should return true for existing file" {
touch testfile.txt
run file_exists testfile.txt
[ "$status" -eq 0 ]
[ "$output" = "true" ]
}

@test "file_exists should return false for non-existing file" {
run file_exists non_existing_file.txt
[ "$status" -eq 0 ]
[ "$output" = "false" ]
}

@test "string_contains should return true if substring is found" {
run string_contains "hello world" "hello"
[ "$status" -eq 0 ]
[ "$output" = "true" ]
}

@test "string_contains should return false if substring is not found" {
run string_contains "hello world" "bye"
[ "$status" -eq 0 ]
[ "$output" = "false" ]
}
EOF

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing!

Signed-off-by: anushkamittal20 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bincapz/pass bincapz/pass Bincapz (aka. malcontent) scan didn't detect any CRITICALs on the scanned packages.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants